<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>轮播</title>
    <style>
        body,
        html {
            height: 100%;
            margin: 0;
            padding: 0;
        }

        .carousel {
            /* 设置相对定位 */
            position: relative;
            height: 100%;
            width: 100%;
            /* 隐藏溢出部分 */
            overflow: hidden;
        }

        .carousel img:first-child {
            /* 设置绝对定位 */
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            /* 初始设置图片透明度为1 */
            opacity: 1;
            /* 设置渐变过渡效果 */
            transition: opacity 2s;
        }

        .carousel img:not(:first-child) {
            /* 设置绝对定位 */
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            /* 初始设置图片透明度为0 */
            opacity: 0;
            /* 设置渐变过渡效果 */
            transition: opacity 2s;
        }
    </style>
    </style>
</head>

<body>
    <!-- <iframe src="header.html" frameborder="0" width="100%" height="100%"></iframe> -->
    <div class="carousel">
        <!-- 轮播图片 -->
        <img src="https://pub-point.hizh.cn/images/202309/26/65122e338bcb2f54e56f4c2e.jpeg">
        <img
            src="https://mmbiz.qpic.cn/mmbiz_jpg/scGBGrsVb5H7c4rrMyVzmjdDicKaDwsetqevwQEmGjqH6OgUqVgOrvf7WaYyZAlicE8lKhugjZ8c5mgzetVT5R6A/640?wx_fmt=jpeg&wxfrom=5&wx_lazy=1&wx_co=1">
        <img
            src="https://mmbiz.qpic.cn/mmbiz_jpg/scGBGrsVb5H7c4rrMyVzmjdDicKaDwset58jsVqDN9qku6kJ54ib79fAHZxU6UeReTBjWayHq67fLx8alTvMAJXQ/640?wx_fmt=jpeg&wxfrom=5&wx_lazy=1&wx_co=1" />
    </div>
</body>
<script>
    let carousel = document.querySelector('.carousel');
    let images = carousel.querySelectorAll('img');
    let currentImgIndex = 0;

    function showNextImage() {
        images[currentImgIndex].style.opacity = 0; // 隐藏当前图片
        currentImgIndex = (currentImgIndex + 1) % images.length; // 计算下一张图片的索引
        images[currentImgIndex].style.opacity = 1; // 显示下一张图片
    }

    // 设置定时器，每5秒切换图片
    setInterval(showNextImage, 3000);
</script>

</html>